#pragma once
#include "afxwin.h"
#include "afxcmn.h"

#include "MvCamera.h"
#include "ForceIpDlg.h"

// 自定义Windows消息ID，预留200个给控件使用
// Custom windows message ID, 200 reserved for control
#define WM_MY_MESSAGE_BASE (200)
#define	WM_MY_DISCOVERY_MESSAGE (WM_USER + WM_MY_MESSAGE_BASE + 1)
#define	WM_MY_DISCONNECT_MESSAGE (WM_USER + WM_MY_MESSAGE_BASE + 2)

// CCameraSubDlg 对话框 | dialog

class CCameraSubDlg 
	: public CDialog
	, public Dahua::IMvCameraSink
{
	DECLARE_DYNAMIC(CCameraSubDlg)

public:
	// 标准构造函数
	// construct function
	CCameraSubDlg(CWnd* pParent = NULL); 
	virtual ~CCameraSubDlg();

public:
	// MvCamera状态回调函数
	// MvCamera status callback function
	virtual void onCameraDisconnect();

	// 自定义函数
	// define function
	void setRect(CRect rect);
	void setCamera(const Dahua::GenICam::ICameraPtr& sptrCamera);

public:
	// MFC事件回调处理函数
	// MFC event callback processing function
	afx_msg void OnBnClickedButtonConnect();
	afx_msg void OnBnClickedButtonDisconnect();
	afx_msg void OnBnClickedButtonPlay();
	afx_msg void OnBnClickedButtonStopplay();
	afx_msg void OnBnClickedButtonSaveconfig();	
	afx_msg void OnCbnSelchangeComboExposureauto();
	afx_msg void OnCbnSelchangeComboExposuremode();
	afx_msg void OnCbnSelchangeComboGainauto();
	afx_msg void OnCbnSelchangeComboImageformat();
	afx_msg void OnCbnSelchangeComboTriggermode();
	afx_msg void OnEnUpdateEditExposure();
	afx_msg void OnEnUpdateEditGain();
	afx_msg void OnEnUpdateEditFramerate();
	afx_msg void OnDeltaposSpinExposure(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDeltaposSpinGain(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnDeltaposSpinFramerate(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedButtonTrigger();
	afx_msg void OnBnClickedButtonForceip();
	afx_msg LRESULT OnMyDisconnectMsg(WPARAM wParam, LPARAM lParam);

	// 对话框数据
	// dialog data
	enum { IDD = IDD_CAMERA_DIALOG };

protected:
	virtual BOOL OnInitDialog();

	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持 | DDX/DDV support

	virtual void OnOK();

	virtual BOOL PreTranslateMessage(MSG* pMsg);

	DECLARE_MESSAGE_MAP()

private:
	void enableProperties(BOOL bEnable);
	void enableWindowAll(BOOL bEnbale);
	void initParamProperty();
	void initComboBoxTypeProperty(Dahua::GenICam::CEnumNode sptrEnumNode, CComboBox* pCmbProperty);
	void initFloatSpinBoxTypeProperty(Dahua::GenICam::CDoubleNode sptrDoubleNode, CEdit* pEditProperty, CSpinButtonCtrl* pSpinBtn);
	void initCameraIpInfo();
	void procSelchangeCombo(Dahua::GenICam::CEnumNode sptrEnumNode, CComboBox* pCmbProperty);
	void procDoubleSpinCtrl(LPNMUPDOWN pNMUpDown, double& valEdit, CEdit* pCtrlEdit);
	bool procTriggerMode( const char* pMode );

private:
	// 各类MFC控件变量
	// Various MFC control variables
	CComboBox						m_cmbExposureAuto;
	CComboBox						m_cmbExposureMode;
	CEdit							m_editExposure;
	CSpinButtonCtrl					m_spinExposure;
	CComboBox						m_cmbGainAuto;
	CEdit							m_editGain;
	CSpinButtonCtrl					m_spinGain;
	CEdit							m_editFrameRate;
	CSpinButtonCtrl					m_spinFrameRate;
	CComboBox						m_cmbImageFormat;
	CComboBox						m_cmbTriggerMode;
	CButton							m_btnTrigger;
	CEdit							m_editGateway;
	CEdit							m_editMask;
	CEdit							m_editIp;
	CListBox						m_lbShowWindow;
	CButton							m_btnForceIp;
	CButton							m_btnConnect;
	CButton							m_btnDisconnect;
	CButton							m_btnPlay;
	CButton							m_btnStopPlay;
	CButton							m_btnSaveConfig;	
	double							m_valExposureTime;
	double							m_valGain;
	double							m_valFrameRate;

	// 自定义变量
	// define variables
	CRect							m_rectDlg;
	Dahua::CMvCameraPtr				m_sptrMvCamera;
	bool							m_bFirstTrigger;
	CForceIpDlg*					m_pForceIpDlg;
	CFont							m_font;	
};
